﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using BesAsm.Emgaats.Core;
using BesAsm.Emgaats.Core.Commands;
using BesAsm.MasterData.Services;
using BesAsm.MasterData.Entities;
using BesAsm.Framework.Reporting;

namespace BesAsm.Emgaats.ModelBuilder.Commands
{
  public class PrepareModelDirectoryCommand : SingleCommand
  {
    private Model _model;

    public PrepareModelDirectoryCommand(Model model)
    {
      _model = model;
    }

    #region IEmgaatsExtensionCommand Members

    public override string Name
    {
      get { return "Prepare model directory"; }
    }

    public override string Description
    {
      get { return "Prepares a directory's structure for building a model"; }
    }

    public override void Execute()
    {
      base.Execute();
      foreach (Simulation simulation in _model.Simulations)
      {
        string modelPath = _model.GetPathIfSet(ModelPathComponent.RootFolder);
        string simulationPath = System.IO.Path.Combine(modelPath, simulation.StormAbbreviation);
        if (!System.IO.Directory.Exists(simulationPath))
        {
          Messenger.ReportMessage("Creating model directory " + simulationPath, 
            BesAsm.Framework.Reporting.ReportableMessageType.Info);
          System.IO.Directory.CreateDirectory(simulationPath);
        }
      }

    }

    public override void Undo()
    {
      throw new NotImplementedException();
    }

    #endregion
  }
}
